//
//  XActionSheetViewController.m
//  iAccountBook
//
//  Created by 侯伟 on 2021/9/21.
//

#import "XActionSheetViewController.h"
#import "UIView+Border.h"
@interface XActionSheetViewController ()

@property(nonatomic,strong)MyLinearLayout* contentLayout;

@end

@implementation XActionSheetViewController

- (void)loadView{
    [super loadView];
    
    MyLinearLayout* popView = [[MyLinearLayout alloc] initWithOrientation:(MyOrientation_Vert)];
    popView.myHorzMargin = 0;
    popView.myBottom = 0;
    popView.myHeight = MyLayoutSize.wrap;
    [self.view addSubview:popView];
    self.popView = popView;


    MyRelativeLayout* titleLayout = [[MyRelativeLayout alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
    titleLayout.backgroundColor = UIColor.whiteColor;
    titleLayout.padding = UIEdgeInsetsMake(0, 20, 0, 20);
    titleLayout.myHeight = 44;
    titleLayout.myMargin = 0;
    [titleLayout setCornerRadius:UIRectCornerTopLeft|UIRectCornerTopRight size:CGSizeMake(16, 16)];
    [popView addSubview:titleLayout];

    
    UIButton* closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"x_add_close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeClicked:) forControlEvents:UIControlEventTouchUpInside];
    closeBtn.mySize = CGSizeMake(32, 32);
    closeBtn.myCenterY = 0;
    closeBtn.myLeft = 0;
    [titleLayout addSubview:closeBtn];


    MyLinearLayout* contentLayout = [[MyLinearLayout alloc] initWithOrientation:(MyOrientation_Horz)];
    contentLayout.backgroundColor = COLOR_BACKGEOUND;
    contentLayout.myHorzMargin = 0;
    contentLayout.myBottom = 0;
    contentLayout.padding = UIEdgeInsetsMake(20, 20, isIphoneX?34:20, 20);
    contentLayout.subviewHSpace = 20;
    contentLayout.myHeight = MyLayoutSize.wrap;
    [popView addSubview:contentLayout];
    _contentLayout = contentLayout;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addBtnsWithIcon:@"x_add_record" sel:@selector(addRecord:)];
    [self addBtnsWithIcon:@"x_add_bookkeeping" sel:@selector(addBookkeeping:)];
    // Do any additional setup after loading the view.
}

- (void)addBtnsWithIcon:(NSString*)iconName sel:(SEL)sel{
    
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:iconName] forState:UIControlStateNormal];
    [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    btn.mySize = CGSizeMake(73, 98);
    btn.myMargin = 0;
    [btn sizeToFit];
    [self.contentLayout addSubview:btn];
}

- (void)closeClicked:(UIButton *)sender {
    [self dismissActionSheetController:NULL];
}

- (void)addRecord:(UIButton*)sender{
    [self dismissActionSheetController:^{
        if(self.block){
            self.block(XDynamicTypeRecord);
        }
    }];
}

- (void)addBookkeeping:(UIButton*)sender{
    [self dismissActionSheetController:^{
        if(self.block){
            self.block(XDynamicTypeBookKeeping);
        }
    }];
}
@end
